<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="com.tjtt.tdm.util.StringUtil"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
    String itemname = request.getParameter("itemname");
	String danwei = request.getParameter("danwei");
	String leibie = request.getParameter("leibie");
	String canshu = request.getParameter("canshu");
	
	if(!StringUtil.isEmpty(itemname)){
	    itemname = StringUtil.encodingUrl(itemname);  
	}
	if(!StringUtil.isEmpty(leibie)){
	    leibie = StringUtil.encodingUrl(leibie);  
	}
   if(!StringUtil.isEmpty(canshu)){
	    canshu = StringUtil.encodingUrl(canshu);  
	}
	request.setAttribute("itemname", itemname);
	request.setAttribute("danwei", danwei);
	request.setAttribute("leibie", leibie);
	request.setAttribute("canshu", canshu);
	request.setAttribute("flag",request.getParameter("flag")); //0:检测参数添加  1：检测参数修改
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 								
	<head> 			
	     <base target="_self"/>					
		<%@ include file="../jslib/jquerylib.jsp" %>
	    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
        <link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
	 <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <c:if test="${requestScope.message!=null}">
		<script type="text/javascript">
 	 		     alert('<c:out value="${requestScope.message}"></c:out>');
 	 		     window.close();
 		</script>
	</c:if>
	
    <script type="text/javascript">
    $().ready(function() {
			
    	// 准备好Options对象
    	var options = {
    	    url:'<%=request.getContextPath()%>/item!saveItemCanshu.action?flag=${flag}&itemname='+encodeURIComponent(encodeURIComponent('${itemname}'))+'&danwei=${danwei}&leibie='+encodeURIComponent(encodeURIComponent('${leibie}'))+'&oldcanshu='+encodeURIComponent(encodeURIComponent('${canshu}')),
    	    dataType:'json',
    	    success: function(data) {
    	      if(data.result=='success'){
				if('${flag}'=='0'){
				  alert("添加成功!");
				}
				else {
				  alert("修改成功!");
				}
				window.close();
    	      }else{
    	      	alert("系统繁忙，请您稍后再试！");
    	      }
    	    }
    	  };
		$('#saveBtn').click(function(){
		    var canshu = $.trim($("#T_JIANCECANSHU").val());
		    if(canshu==''){
		      alert("请填写检测参数");
		      return false;
		    }
		  
		    var valueMsg1 = "T.T_ITEMNAME='"+$.trim($("#T_ITEMNAME").val())+"' and T.T_JIANCEDANWEI='${danwei}' and T.T_JIACELEIBIE='"+$("#T_JIACELEIBIE").val()+"' and T.T_JIANCECANSHU='"+canshu+"'";
    	   //添加
    	   if('${flag}'=='0'){
    	      var result = checkMessageWeiyi('GWM_ITEM T  ','',valueMsg1);
    	      if(result=='true'){
    	         alert("检测参数已存在,请重新输入!");
    	         return false;
    	      }
    	   }else{
    	     valueMsg1 = valueMsg1+" and T.T_JIANCECANSHU !='"+'${canshu}'+"'";
    	     var result = checkMessageWeiyi('GWM_ITEM T  ','',valueMsg1);
    	     if(result=='true'){
    	         alert("检测参数已存在,请重新输入!");
    	         return false;
    	     }
    	   }
			$('#pageFrom').ajaxSubmit(options);
			return false;
		});
		
		$('#closeBtn').click(function(){
			window.close();
		});
	});
	
	
	//判断是否唯一
	function checkMessageWeiyi(tableName,columName,valueMsg){
	  var flag = 'error';
	  var  params = {
	               "tableName":tableName,
	               "flowtaskid":'',
	               "columName":columName,
	               "valueMsg":encodeURIComponent(valueMsg)
	              };
	  $.ajax({
			type: "POST",
			url :'<%=request.getContextPath()%>/auto!checkMessageWeiyi.action',  
			dataType: "json",
			data:params,
			async: false,//取消异步提交
			success : function(data, textStatus) {  
				if(data.result=='error'){
				   alert("校验唯一性失败!");
				   flag = 'error';
				}
				flag = data.result;
			},
			error:function(){}
		});
		return flag;
	}
</script>
<style type="text/css">
 		body{
 			background:#ffffff; background-image:url(images/);
 		}
   		html{
		    overflow-x: hidden;
			overflow-y: hidden;
		}  	
		.formTableNew textarea{border: 1px solid #999;padding: 5px;width: 760px;-moz-border-radius: 3px;border-radius: 3px;margin-bottom: 5px;color: #666;background: url(../images/input_bg.gif) repeat-x top;}
   </style>
</head>
<body >
  	<form  id="pageFrom" name="pageFrom" class="easyui-form" data-options="novalidate:true" method="post">
  		<input type="hidden" id="formid" name="formid" value="3942"/>
  		<input type="hidden" id="columns" name="columns" value="T_ITEMNAME,T_JIANCEDANWEI,T_GONGSIDAIMA,T_JIANCEDIDIAN,T_JIANCEBUMEN,T_JIACELEIBIE,T_JIANCEMONEY,"/>
  		<table width="100%" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
  			<tr>
	  			<td align="right">检测项目：</td>
	  			<td align="left">
	  			   <input  type="text"  id="T_ITEMNAME"   name="T_ITEMNAME" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="${itemname }" readonly/>
	  			</td>
	  	   </tr>
	  	   <tr>
  		       <td align="right">检测类别：</td>
  		       <td align="left">
  		          <input  type="text"  id="T_JIACELEIBIE"   name="T_JIACELEIBIE" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="${leibie }" readonly />
  		       </td>
  		   </tr>
  		   <tr>
  		       <td align="right">检测参数：</td>
  		       <td align="left">
  		          <input  type="text"  id="T_JIANCECANSHU"   name="T_JIANCECANSHU" style="border: 1px solid #999;padding: 5px;width: 250px;"  value="${canshu }" />
  		       </td>
  		   </tr>
		   <tr>
		      <td colspan="2" align="center">
		    	<input id="saveBtn" type="button" value="保 存" class="form_bt_orange" />
		      	<input type="button" id="closeBtn" value="取 消" class="form_bt_grey" />
		      </td>
		   </tr>	
		</table>
	</form>
  </body>
</html>

